[SCM]Use Gradle - lifuzu/cafe GitHub Wiki

Define a task in build.gradle:

task hello << {
    println 'Hello world!'
}

then run:

gradle hello

Use Groovy function in Gradle task:

task upper << {
    String someString = 'mY_nAmE'
    println "Original: " + someString 
    println "Upper case: " + someString.toUpperCase()
}

task count << {
    4.times { print "$it " }
}

then run:

gradle -q upper

or

gradle -q count

Declare the dependency between tasks:

task hello << {
    println 'Hello world!'
}
task intro(dependsOn: hello) << {
    println "I'm Gradle"
}

then run:

gradle -q intro

Setup a default tasks

defaultTasks 'clean', 'run'

task clean << {
    println 'Default Cleaning!'
}

task run << {
    println 'Default Running!'
}

task other << {
    println "I'm not a default task!"
}

then run

gradle

List the tasks of a project

gradle tasks

Use the Java plugin:

apply plugin: 'java'

Add Maven repository:

repositories {
    mavenCentral()
}

Add some dependecies:

dependencies {
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
    testCompile group: 'junit', name: 'junit', version: '4.+'
}

Customize the properties of the project:

sourceCompatibility = 1.5			// specify the Java version our source is written in
version = '1.0'								// specify the version number for our Java project
jar {													// add some attributes to the JAR manifest
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
    }
}

test {												// add a test system property
    systemProperties 'property': 'value'
}

Publish the JAR file

uploadArchives {
    repositories {
       flatDir {
           dirs 'repos'
       }
    }
}

then run:

gradle uploadArchives

Create an Eclipse project:

apply plugin: 'eclipse'

then run:

gradle eclipse